package com.jyw.business.de.domain.dto.web;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.jyw.business.de.domain.DeDemandAnalyze;
import com.jyw.common.annotation.Excel;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import com.jyw.common.utils.bean.BeanUtils;
import com.jyw.system.domain.vo.SimpleFileVo;
import com.jyw.system.utils.FileUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Data
@ApiModel("需求分析请求实体")
public class DemandAnalyzeAddDto {

    /** 需求主键 */
    @ApiModelProperty("需求主键")
    @NotNull(message = "需求主键不能为空")
    private Long demandId;

    /** 需求分析人 */
    @ApiModelProperty("需求分析人(逗号分割)")
    @NotEmpty(message = "需求分析人不能为空")
    private List<Long> analyzeUser;

    /** 需求是否可行 1是 0否 */
    @ApiModelProperty("需求是否可行 1是 0否")
    @NotNull(message = "需求是否可行不能为空")
    private Integer demandFeasible;

    /** 需求是否必要 1必要 0不必要 */
    @ApiModelProperty("需求是否必要 1必要 0不必要")
    @NotNull(message = "需求是否必要不能为空")
    private Integer demandRequired;

    /** 涉及系统 */
    @ApiModelProperty("涉及系统(逗号拼接)")
    private List<String> analyzeSystem;

    /** 分析情况说明 */
    @ApiModelProperty("分析情况说明")
    @NotEmpty(message = "分析情况说明不能为空")
    private String analyzeRemark;

    /** 分析附件 */
    @ApiModelProperty("分析附件")
    private List<SimpleFileVo> analyzeEnclosure;

    public DeDemandAnalyze buildAnalyze() {
        DeDemandAnalyze deDemandAnalyze = new DeDemandAnalyze();
        BeanUtils.copyProperties(this,deDemandAnalyze);
        if(!CollectionUtils.isEmpty(getAnalyzeSystem())){
            deDemandAnalyze.setAnalyzeSystem(getAnalyzeSystem().stream().collect(Collectors.joining(",")));
        }
        if(!CollectionUtils.isEmpty(getAnalyzeUser())){
            deDemandAnalyze
                    .setAnalyzeUser(getAnalyzeUser().stream().map(data->data.toString())
                    .collect(Collectors.joining(",")));
        }
        deDemandAnalyze.setAnalyzeEnclosure(FileUtils.fileToId(getAnalyzeEnclosure()));
        deDemandAnalyze.setCreateTime(DateUtils.getNowDate());
        deDemandAnalyze.setCreateUser(SecurityUtils.getUserId());
        return deDemandAnalyze;
    }
}
